﻿using AutoMapper;
using Domain.Entity;
using Domain.Entity.zct;
using Domain.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.UserService
{

    public class UserService : IUserService
    {
        private readonly IUserRepository userRepository;
        private readonly IMapper mapper;

        public UserService(IUserRepository userRepository, IMapper mapper)
        {
            this.userRepository = userRepository;
            this.mapper = mapper;

        }

        //查询所有用户
        public async Task<List<User>> GetAllUser()
        {
            return await userRepository.GetAllUser();
        }

        //登录
        public async Task<UserRole> GetUser(string account, string pwd)
        {
            return await userRepository.GetUser(account, pwd);
        }

        //根据部门id查询独赢用户
        public async Task<List<User>> GetUserByDeptId(int depid)
        {
            return await userRepository.GetUserByDeptId(depid);
        }


        //根据用户id查询用户
        public Task<User> GetUserById(int uid)
        {
            return userRepository.GetUserById(uid);
        }


        //修改个人信息
        public Task<int> UpdateInfo(string? name, string? sex, string? phone, string? avatar, int id)
        {
            return userRepository.UpdateInfo(name, sex, phone, avatar,id);
        }


        //修改密码
        public Task<int> UpdatePwd(int uid, string pwd)
        {
            return userRepository.UpdatePwd(uid, pwd);
        }

        //添加
        public async Task<int> GetAdd(EditUserWithRolesDto editUserWithRolesDto)
        {
            User user = mapper.Map<User>(editUserWithRolesDto.editUserDto);
            return await userRepository.GetAdd(editUserWithRolesDto.RoleIds, user);
        }

        //全部查
        public async Task<FenYe<User>> GetAll(FenYe<User> fenYe)
        {
            return await userRepository.GetAll(fenYe);
        }

        //条件查
        public async Task<FenYe<User>> GetCondition(FenYe<User> fenYe, string? User_account, string? User_name, int? Position_id, int? User_status)
        {
            return await userRepository.GetCondition(fenYe, User_account, User_name, Position_id, User_status);
        }

        //停用
        public async Task<int> GetDeactivated(int id)
        {
            return await userRepository.GetDeactivated(id);
        }

        //删除
        public async Task<int> GetDelete(int id)
        {
            return await userRepository.GetDelete(id);
        }

        //修改
        public async Task<int> GetEdit(EditUserWithRolesDto editUserWithRolesDto)
        {
            User user = mapper.Map<User>(editUserWithRolesDto.editUserDto);
            return await userRepository.GetEdit(editUserWithRolesDto.RoleIds, user);
        }

        //启用
        public async Task<int> GetEnable(int id)
        {
            return await userRepository.GetEnable(id);
        }

        //id查询
        public async Task<User> GetID(int id)
        {
            return await userRepository.GetID(id);
        }
    }
}
